#include "Tank.h"
#include "texturemanager.h"
#include "Direction.h"


Texture* Tank::m_animate[20] = {0};

Tank::Tank()
	: Sprite()
{

	//N,NW,W,SW,S,SE,E,NE
	m_animate[NORTH] = TextureManager::Instance()->GetTexture("asset/tank_n.png");
	m_animate[NORTH + WEST] = TextureManager::Instance()->GetTexture("asset/tank_nw.png");
	m_animate[WEST] = TextureManager::Instance()->GetTexture("asset/tank_w.png");
	m_animate[SOUTH + WEST] = TextureManager::Instance()->GetTexture("asset/tank_sw.png");
	m_animate[SOUTH] = TextureManager::Instance()->GetTexture("asset/tank_s.png");
	m_animate[SOUTH + EAST] = TextureManager::Instance()->GetTexture("asset/tank_se.png");
	m_animate[EAST] = TextureManager::Instance()->GetTexture("asset/tank_e.png");
	m_animate[NORTH + EAST] = TextureManager::Instance()->GetTexture("asset/tank_ne.png");
	//Handle special direction keys to resolve key competition issues
	m_animate[NORTH + SOUTH] = TextureManager::Instance()->GetTexture("asset/tank_n.png");
	m_animate[WEST + EAST] = TextureManager::Instance()->GetTexture("asset/tank_e.png");
	m_animate[NORTH + SOUTH + EAST] = TextureManager::Instance()->GetTexture("asset/tank_n.png");
	m_animate[NORTH + SOUTH + WEST] = TextureManager::Instance()->GetTexture("asset/tank_n.png");
	m_animate[NORTH + WEST + EAST] = TextureManager::Instance()->GetTexture("asset/tank_n.png");
	m_animate[SOUTH + WEST + EAST] = TextureManager::Instance()->GetTexture("asset/tank_s.png");
	m_animate[NORTH + SOUTH + WEST + EAST] = TextureManager::Instance()->GetTexture("asset/tank_e.png");

	SetTexture(m_animate[EAST]);
	SetScale(1.2);
}

void Tank::Move(int direction) {
	if (!direction) {
		direction = EAST;
	}
	m_pTexture = m_animate[direction];

	//tank move
	if (direction & NORTH) {
		m_y -= m_speed;
	}
	if (direction & WEST) {
		m_x -= m_speed;
	}
	if (direction & SOUTH) {
		m_y += m_speed;
	}
	if (direction & EAST) {
		m_x += m_speed;
	}
	
}